import com.zgr.ssm.entity.FileEntity;
import com.zgr.ssm.entity.User;
import com.zgr.ssm.mapper.FileMapper;
import com.zgr.ssm.mapper.UserMapper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class UserMapperCase {
    private AbstractApplicationContext ac;
    private UserMapper userMapper;
    private FileMapper fileMapper;

    @Test
    public void insert(){
        System.out.println(ac);
        User user = new User();
        user.setUsername("cc");
        user.setPwd("cc");
        user.setEmail("asdddd");
        Integer rows = userMapper.insert(user);
    }

    @Test
    public void findByUsername(){
        String username = "aa";
        User user = userMapper.findByUsername(username);
        System.out.println("user: " + user);
    }

    @Test
    public void insertF(){
        FileEntity f = new FileEntity();
        f.setId(1);
        f.setUserId(1);
        f.setFileName("aaa");
        Integer rows = fileMapper.insert(f);
    }

    @Test
    public void findByUid(){
        int id = 1;
        List<FileEntity> f = fileMapper.findByUid(id);
        System.out.println(f);

    }

    @Before
    public void doBefore(){
        ac = new ClassPathXmlApplicationContext("spring-dao.xml");
        fileMapper = ac.getBean("fileMapper", FileMapper.class);
    }

    @After
    public void doAfter(){
        ac.close();
    }
}
